
#ifndef UCDB_DBDWFHOST_H
#define UCDB_DBDWFHOST_H

#include "zdbmain.h"
#include "zacstring.h"

#pragma pack (push, 8)

class UcImpUnderlayLayer;
class IUcReadStream;
class UcUnderlayLayer
{
public:
    UcUnderlayLayer();
    ~UcUnderlayLayer();

    typedef enum {
        kOff=0,
        kOn=1} State;

    UcString name() const;
    State state() const;
    Ucad::ErrorStatus setName(const UcString& name);
    Ucad::ErrorStatus setState(State state);

	UcUnderlayLayer const & operator =(UcUnderlayLayer const &);
	UcUnderlayLayer( UcUnderlayLayer const &);

private:
    UcImpUnderlayLayer* m_pImpUnderlayLayer;
};

struct UcDbUnderlayDrawContext
{

     ZSoft::UInt8 contrast;

     ZSoft::UInt8 fade;

     bool monochrome;

     bool adjustColorForBackground;

     UcUnderlayLayer** pLayers;
};

const int kItemVersionNumber = 1;

class ZSOFT_NO_VTABLE UcDbUnderlayItem
{
public:
    virtual ~UcDbUnderlayItem() = 0;
    virtual UcString getName() const = 0;
    virtual Ucad::ErrorStatus getThumbnail(
                                BITMAPINFO*& thumbnail) const = 0;
    virtual Ucad::ErrorStatus getExtents(
                                UcGePoint2d& min,
                                UcGePoint2d& max) const = 0;
    virtual UcDb::UnitsValue getUnits() const = 0;
    virtual bool usingPartialContent() const = 0;
    virtual Ucad::ErrorStatus draw(
        UcGiWorldDraw* pWorldDraw,
        UcGiViewportDraw* pViewportDraw,
        const UcDbUnderlayDrawContext& context) const = 0;
    virtual UcGeMatrix3d modelTransform() const = 0;
    virtual Ucad::ErrorStatus getOsnapPoints(const UcGeMatrix3d& modelToWorld,
                                             UcDb::OsnapMode osnapMode,
                                             ZSoft::GsMarker   gsSelectionMark,
                                             const UcGePoint3d&  pickPoint,
                                             const UcGePoint3d&  lastPoint,
                                             const UcGeMatrix3d& viewXform,
                                             UcGePoint3dArray&      snapPoints,
                                             UcDbIntArray &   geomIds)
                                             const = 0;
    virtual UcDbEntity* getSubEntityAtGsMarker(const UcGeMatrix3d& modelToWorld,ZSoft::GsMarker gsSelectionMark) const = 0;
    virtual Ucad::ErrorStatus intersectWith(const UcGeMatrix3d& modelToWorld,
                                            const UcDbEntity* pEnt,
                                            UcDb::Intersect intType,
                                            const UcGePlane* projPlane,
                                            UcGePoint3dArray& points,
                                            ZSoft::GsMarker thisGsMarker,
                                            ZSoft::GsMarker otherGsMarker) const = 0;
    virtual ZSoft::UInt32 underlayLayerCount() const { return 0; }
    virtual Ucad::ErrorStatus getUnderlayLayer(int idx, UcUnderlayLayer& layer) const { return Ucad::eNotImplemented; }
    int version() const;
};

class ZSOFT_NO_VTABLE UcDbDgnUnderlayItem : public UcDbUnderlayItem
{
public:
    virtual bool useMasterUnits() const = 0;
    virtual void setUseMasterUnits(bool bUseMasterUnits) = 0;
    virtual bool showRasterRef() const = 0;
    virtual void setShowRasterRef(bool bShow) = 0;
};

class ZSOFT_NO_VTABLE UcDbUnderlayFile
{
public:
    virtual ~UcDbUnderlayFile() = 0;
    virtual int getItemCount() const = 0;
    virtual Ucad::ErrorStatus getItem(
                                int i,
                                UcDbUnderlayItem*& pItem) const = 0;
    virtual Ucad::ErrorStatus getItem(
                                const ZTCHAR* name,
                                UcDbUnderlayItem*& pItem) const = 0;
};

class ZSOFT_NO_VTABLE UcDbUnderlayHost
{
public:
    virtual Ucad::ErrorStatus getFile(
                                const ZTCHAR* fullPath,
                                const wchar_t* password,
                                UcDbUnderlayFile*& pFile) const = 0;
	virtual Ucad::ErrorStatus getFile(
                                IUcReadStream* pFileStream,
                                const wchar_t* password, 
                                UcDbUnderlayFile*& pFile) const = 0;
    static void getAdjustedColor(
                               UcGeVector3d& rgbResult,
                               const UcGeVector3d& rgbInputColor,
                               const UcGeVector3d& rgbCurrentBackgroundColor,
                               const UcGeVector3d& hslFadedContrastColor,
                               const UcDbUnderlayDrawContext& drawContext);
protected:

    virtual ~UcDbUnderlayHost() = 0;
};

UCDB_PORT UcDbUnderlayHost*
ucdbGetCurrentDwfHost();

UCDB_PORT UcDbUnderlayHost*
ucdbSetCurrentDwfHost(
    UcDbUnderlayHost* pHost);

UCDB_PORT UcDbUnderlayHost*
ucdbGetCurrentDgnHost();

UCDB_PORT UcDbUnderlayHost*
ucdbSetCurrentDgnHost(
    UcDbUnderlayHost* pHost);

UCDB_PORT UcDbUnderlayHost*
ucdbGetCurrentDgnDocHost();

UCDB_PORT UcDbUnderlayHost*
ucdbSetCurrentDgnDocHost(
    UcDbUnderlayHost* pHost);

UCDB_PORT void
ucdbConvertRgbToHsl(
           const UcGeVector3d& rgb,
           UcGeVector3d& hsl
           );

UCDB_PORT void
ucdbConvertHslToRgb(
           const UcGeVector3d& hsl,
           UcGeVector3d& rgb);

#pragma pack (pop)

#endif
